#ifndef THINK_THINK_CACHE_H
#define THINK_THINK_CACHE_H

static char* think_cache =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"use think\\cache\\Driver;\n"
	"\n"
	"class Cache\n"
	"{\n"
	"    /**\n"
	"     * @var array 缓存的实例\n"
	"     */\n"
	"    public static $instance = [];\n"
	"\n"
	"    /**\n"
	"     * @var int 缓存读取次数\n"
	"     */\n"
	"    public static $readTimes = 0;\n"
	"\n"
	"    /**\n"
	"     * @var int 缓存写入次数\n"
	"     */\n"
	"    public static $writeTimes = 0;\n"
	"\n"
	"    /**\n"
	"     * @var object 操作句柄\n"
	"     */\n"
	"    public static $handler;\n"
	"\n"
	"    /**\n"
	"     * 连接缓存驱动\n"
	"     * @access public\n"
	"     * @param  array       $options 配置数组\n"
	"     * @param  bool|string $name    缓存连接标识 true 强制重新连接\n"
	"     * @return Driver\n"
	"     */\n"
	"    public static function connect(array $options = [], $name = false)\n"
	"    {\n"
	"        $type = !empty($options[\'type\']) ? $options[\'type\'] : \'File\';\n"
	"\n"
	"        if (false === $name) {\n"
	"            $name = md5(serialize($options));\n"
	"        }\n"
	"\n"
	"        if (true === $name || !isset(self::$instance[$name])) {\n"
	"            $class = false === strpos($type, \'\\\\\') ?\n"
	"            \'\\\\think\\\\cache\\\\driver\\\\\' . ucwords($type) :\n"
	"            $type;\n"
	"\n"
	"            // 记录初始化信息\n"
	"            App::$debug && Log::record(\'[ CACHE ] INIT \' . $type, \'info\');\n"
	"\n"
	"            if (true === $name) {\n"
	"                return new $class($options);\n"
	"            }\n"
	"\n"
	"            self::$instance[$name] = new $class($options);\n"
	"        }\n"
	"\n"
	"        return self::$instance[$name];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 自动初始化缓存\n"
	"     * @access public\n"
	"     * @param  array $options 配置数组\n"
	"     * @return Driver\n"
	"     */\n"
	"    public static function init(array $options = [])\n"
	"    {\n"
	"        if (is_null(self::$handler)) {\n"
	"            if (empty($options) && \'complex\' == Config::get(\'cache.type\')) {\n"
	"                $default = Config::get(\'cache.default\');\n"
	"                // 获取默认缓存配置，并连接\n"
	"                $options = Config::get(\'cache.\' . $default[\'type\']) ?: $default;\n"
	"            } elseif (empty($options)) {\n"
	"                $options = Config::get(\'cache\');\n"
	"            }\n"
	"\n"
	"            self::$handler = self::connect($options);\n"
	"        }\n"
	"\n"
	"        return self::$handler;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 切换缓存类型 需要配置 cache.type 为 complex\n"
	"     * @access public\n"
	"     * @param  string $name 缓存标识\n"
	"     * @return Driver\n"
	"     */\n"
	"    public static function store($name = \'\')\n"
	"    {\n"
	"        if (\'\' !== $name && \'complex\' == Config::get(\'cache.type\')) {\n"
	"            return self::connect(Config::get(\'cache.\' . $name), strtolower($name));\n"
	"        }\n"
	"\n"
	"        return self::init();\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 判断缓存是否存在\n"
	"     * @access public\n"
	"     * @param  string $name 缓存变量名\n"
	"     * @return bool\n"
	"     */\n"
	"    public static function has($name)\n"
	"    {\n"
	"        self::$readTimes++;\n"
	"\n"
	"        return self::init()->has($name);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 读取缓存\n"
	"     * @access public\n"
	"     * @param  string $name    缓存标识\n"
	"     * @param  mixed  $default 默认值\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function get($name, $default = false)\n"
	"    {\n"
	"        self::$readTimes++;\n"
	"\n"
	"        return self::init()->get($name, $default);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 写入缓存\n"
	"     * @access public\n"
	"     * @param  string   $name   缓存标识\n"
	"     * @param  mixed    $value  存储数据\n"
	"     * @param  int|null $expire 有效时间 0为永久\n"
	"     * @return boolean\n"
	"     */\n"
	"    public static function set($name, $value, $expire = null)\n"
	"    {\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->set($name, $value, $expire);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 自增缓存（针对数值缓存）\n"
	"     * @access public\n"
	"     * @param  string $name 缓存变量名\n"
	"     * @param  int    $step 步长\n"
	"     * @return false|int\n"
	"     */\n"
	"    public static function inc($name, $step = 1)\n"
	"    {\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->inc($name, $step);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 自减缓存（针对数值缓存）\n"
	"     * @access public\n"
	"     * @param  string $name 缓存变量名\n"
	"     * @param  int    $step 步长\n"
	"     * @return false|int\n"
	"     */\n"
	"    public static function dec($name, $step = 1)\n"
	"    {\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->dec($name, $step);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 删除缓存\n"
	"     * @access public\n"
	"     * @param  string $name 缓存标识\n"
	"     * @return boolean\n"
	"     */\n"
	"    public static function rm($name)\n"
	"    {\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->rm($name);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 清除缓存\n"
	"     * @access public\n"
	"     * @param  string $tag 标签名\n"
	"     * @return boolean\n"
	"     */\n"
	"    public static function clear($tag = null)\n"
	"    {\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->clear($tag);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 读取缓存并删除\n"
	"     * @access public\n"
	"     * @param  string $name 缓存变量名\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function pull($name)\n"
	"    {\n"
	"        self::$readTimes++;\n"
	"        self::$writeTimes++;\n"
	"\n"
	"        return self::init()->pull($name);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 如果不存在则写入缓存\n"
	"     * @access public\n"
	"     * @param  string $name   缓存变量名\n"
	"     * @param  mixed  $value  存储数据\n"
	"     * @param  int    $expire 有效时间 0为永久\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function remember($name, $value, $expire = null)\n"
	"    {\n"
	"        self::$readTimes++;\n"
	"\n"
	"        return self::init()->remember($name, $value, $expire);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 缓存标签\n"
	"     * @access public\n"
	"     * @param  string       $name    标签名\n"
	"     * @param  string|array $keys    缓存标识\n"
	"     * @param  bool         $overlay 是否覆盖\n"
	"     * @return Driver\n"
	"     */\n"
	"    public static function tag($name, $keys = null, $overlay = false)\n"
	"    {\n"
	"        return self::init()->tag($name, $keys, $overlay);\n"
	"    }\n"
	"\n"
	"}\n"
	"\n"
;
#endif